package com.medical.lsq.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.medical.lsq.dao.SysPolicyMapper;
import com.medical.lsq.entity.SysPolicy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Timestamp;
import java.util.List;

@Service
@Transactional
public class PolicyService {
@Autowired
private SysPolicyMapper policyMapper;
/**
 * 添加慢病政策信息
 * @param sysPolicy
 */
public void add(SysPolicy sysPolicy) {
        sysPolicy.setCreateTime(new Timestamp(System.currentTimeMillis()));
        sysPolicy.setUpdateTime(new Timestamp(System.currentTimeMillis()));
        policyMapper.insertSelective(sysPolicy);
        }
/**
 * 根据主键ID删除一条信息
 * @param id
 */
public void delete(Integer id) {policyMapper.deleteByPrimaryKey(id);}

/**
 * 根据对象信息进行更新
 * @param sysPolicy
 */
public void edit(SysPolicy sysPolicy) {
        sysPolicy.getUpdateTime(new Timestamp(System.currentTimeMillis()));
        policyMapper.updateByPrimaryKeySelective(sysPolicy);
        }
/**
 * 查询所有慢病政策信息，可以进行模糊查询，需要进行分页
 * @return 慢病政策信息列表
 */
public PageInfo<SysPolicy> getPolicyList(Integer currentPage, Integer limit, String policyYear) {
        //利用PageHelper分页查询 注意：这个一定要放查询语句的前一行,否则无法进行分页,因为它对紧随其后第一个sql语句有效
        PageHelper.startPage(currentPage, limit);
        List<SysPolicy> list = policyMapper.getPolicyList(policyYear);
        PageInfo<SysPolicy> pageInfo = new PageInfo<SysPolicy>(list);
        return pageInfo;
        }

        public SysPolicy getPolicy(Integer id) {
                return policyMapper.selectByPrimaryKey(id);
        }
}
